import {Button, Col, Row} from "antd";
import {useEffect, useState} from "react";
import {invoke} from "@tauri-apps/api/core";

import {useNavigate} from 'react-router-dom';

const AppHome = () => {
    const navigate = useNavigate();
    const [disksInfo, setDisksInfo] = useState([])
    useEffect(() => {
        invoke("disks_info").then(res => {
            console.log("res diskinfo", res)
            setDisksInfo(res)
            let key = res[0].mount
        })
    }, []);
    const toDirlist = (diskPath) => {
        navigate(`/file/dirlist`, {
            state: {
                diskPath
            }
        });
    }
    return (
        <div style={{margin: "10% 24px 64px", width: "100%"}}>
            <Row gutter={[16, 24]}>
                {disksInfo.map((item, i) => {
                    const id = String(i + 1);
                    const diskPath = item.mount.replace("\\", "");
                    return <Col style={{textAlign: "center"}} span={6}>
                        <Button style={{width: "95px", height: "75px", fontSize: "18px"}}
                                onClick={() => {
                                    toDirlist(item.mount)
                                }}
                        >{diskPath} 盘</Button>
                    </Col>
                })}
            </Row>
        </div>
    )
}
export default AppHome;